package cn.jy.nvr.service.impl;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Random;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.jy.nvr.datasource.DataSourceConst;
import cn.jy.nvr.datasource.DataSourceContextHolder;
import cn.jy.nvr.domain.jiaying.Aphereses;
import cn.jy.nvr.domain.jiaying.ExceptionCollections;
import cn.jy.nvr.domain.jiaying.GJZBodyCheck;
import cn.jy.nvr.domain.jiaying.GJZXPCheck;
import cn.jy.nvr.domain.jiaying.GJZXQDYQD;
import cn.jy.nvr.domain.jiaying.GJZXX;
import cn.jy.nvr.domain.jiaying.GJZ_Cost_Release;
import cn.jy.nvr.domain.jiaying.GJZ_Heat;
import cn.jy.nvr.domain.jiaying.GJZ_SAMPLE_ASSAY;
import cn.jy.nvr.domain.jiaying.GJZ_Sample_collection;
import cn.jy.nvr.domain.jiaying.GjzZwTable;
import cn.jy.nvr.domain.jiaying.Sfproviderreg;
import cn.jy.nvr.domain.jiaying.SystemLogJiaying;
import cn.jy.nvr.domain.jiaying.distribution;
import cn.jy.nvr.domain.jiaying.userSet;
import cn.jy.nvr.domain.jingying.AssayRecord;
import cn.jy.nvr.domain.jingying.AssayRecordRegister;
import cn.jy.nvr.domain.jingying.AssayXQDY;
import cn.jy.nvr.domain.jingying.BodyCheckLastRecord;
import cn.jy.nvr.domain.jingying.BodyCheckRecord;
import cn.jy.nvr.domain.jingying.CardTable;
import cn.jy.nvr.domain.jingying.CollectionRecord;
import cn.jy.nvr.domain.jingying.KHCSL;
import cn.jy.nvr.domain.jingying.KUSE;
import cn.jy.nvr.domain.jingying.KUSEList;
import cn.jy.nvr.domain.jingying.PlasmStock;
import cn.jy.nvr.domain.jingying.ProviderBaseInfo;
import cn.jy.nvr.domain.jingying.ProviderRegister;
import cn.jy.nvr.domain.jingying.ProviderZwTable;
import cn.jy.nvr.domain.jingying.RateRecord;
import cn.jy.nvr.domain.jingying.Registerteminfo;
import cn.jy.nvr.domain.jingying.SystemLog;
import cn.jy.nvr.mapper.jiaying.ApheresesMapper;
import cn.jy.nvr.mapper.jiaying.DistributionMapper;
import cn.jy.nvr.mapper.jiaying.ExceptionCollectionsMapper;
import cn.jy.nvr.mapper.jiaying.GJZBodyCheckMapper;
import cn.jy.nvr.mapper.jiaying.GJZXPCheckMapper;
import cn.jy.nvr.mapper.jiaying.GJZXPDYPHMapper;
import cn.jy.nvr.mapper.jiaying.GJZXQDYQDMapper;
import cn.jy.nvr.mapper.jiaying.GJZXXMapper;
import cn.jy.nvr.mapper.jiaying.GJZ_Cost_ReleaseMapper;
import cn.jy.nvr.mapper.jiaying.GJZ_HeatMapper;
import cn.jy.nvr.mapper.jiaying.GJZ_Sample_ASSAYMapper;
import cn.jy.nvr.mapper.jiaying.GJZ_Sample_CollectionMapper;
import cn.jy.nvr.mapper.jiaying.GjzZwTableMapper;
import cn.jy.nvr.mapper.jiaying.SfproviderregMapper;
import cn.jy.nvr.mapper.jiaying.SystemLogJiayingMapper;
import cn.jy.nvr.mapper.jiaying.userSetMapper;
import cn.jy.nvr.mapper.jingying.AssayRecordMapper;
import cn.jy.nvr.mapper.jingying.AssayRecordRegisterMapper;
import cn.jy.nvr.mapper.jingying.AssayXQDYMapper;
import cn.jy.nvr.mapper.jingying.BodyCheckLastRecordMapper;
import cn.jy.nvr.mapper.jingying.BodyCheckRecordMapper;
import cn.jy.nvr.mapper.jingying.CardTableMapper;
import cn.jy.nvr.mapper.jingying.CollectionRecordMapper;
import cn.jy.nvr.mapper.jingying.KHCSLMapper;
import cn.jy.nvr.mapper.jingying.KUSEListMapper;
import cn.jy.nvr.mapper.jingying.KUSEMapper;
import cn.jy.nvr.mapper.jingying.PlasmStockMapper;
import cn.jy.nvr.mapper.jingying.ProviderBaseInfoMapper;
import cn.jy.nvr.mapper.jingying.ProviderRegisterMapper;
import cn.jy.nvr.mapper.jingying.ProviderZwTableMapper;
import cn.jy.nvr.mapper.jingying.RateRecordMapper;
import cn.jy.nvr.mapper.jingying.RegisterteminfoMapper;
import cn.jy.nvr.mapper.jingying.SystemLogMapper;
import cn.jy.nvr.service.Sync2jyInterface;
import cn.jy.nvr.utils.Base64Utils;
import cn.jy.nvr.utils.DateTools;
import cn.jy.nvr.utils.NumberTools;

@Service("sync2Jingying")
public class Sync2JingyingImpl implements Sync2jyInterface {

	@Autowired
	private SfproviderregMapper sfproviderregMapper;
	@Autowired
	private GJZXXMapper GJZXXMapper;
	@Autowired
	private AssayRecordMapper assayRecordMapper;
	@Autowired
	private AssayXQDYMapper assayXQDYMapper;
	@Autowired
	private BodyCheckLastRecordMapper bodyCheckLastRecordMapper;
	@Autowired
	private BodyCheckRecordMapper bodyCheckRecordMapper;
	@Autowired
	private CardTableMapper cardTableMapper;
	@Autowired
	private CollectionRecordMapper collectionRecordMapper;
	@Autowired
	private KHCSLMapper kHCSLMapper;
	@Autowired
	private KUSEListMapper kUSEListMapper;
	@Autowired
	private KUSEMapper kUSEMapper;
	@Autowired
	private ProviderRegisterMapper providerRegisterMapper;
	@Autowired
	private ProviderBaseInfoMapper providerBaseInfoMapper;
	@Autowired
	private RateRecordMapper rateRecordMapper;
	@Autowired
	private SystemLogMapper systemLogMapper;
	@Autowired
	private SystemLogJiayingMapper systemLogJiayingMapper;
	@Autowired
	private ApheresesMapper apheresesMapper;
	@Autowired
	private GJZ_Cost_ReleaseMapper GJZ_Cost_ReleaseMapper;
	@Autowired
	private GJZ_HeatMapper GJZ_HeatMapper;
	@Autowired
	private GJZ_Sample_ASSAYMapper GJZ_Sample_ASSAYMapper;
	@Autowired
	private GJZ_Sample_CollectionMapper GJZ_Sample_CollectionMapper;
	@Autowired
	private GJZBodyCheckMapper GJZBodyCheckMapper;
	@Autowired
	private GJZXPCheckMapper GJZXPCheckMapper;
	@Autowired
	private GJZXPDYPHMapper GJZXPDYPHMapper;
	@Autowired
	private userSetMapper userSetMapper;
	@Autowired
	private GjzZwTableMapper gjzZwTableMapper;
	@Autowired
	private ProviderZwTableMapper providerZwTableMapper;
	@Autowired
	private RegisterteminfoMapper registerteminfoMapper;
	@Autowired
	private DistributionMapper distributionMapper;
	@Autowired
	private GJZXQDYQDMapper GJZXQDYQDMapper;
	@Autowired
	private AssayRecordRegisterMapper assayRecordRegisterMapper;
	@Autowired
	private PlasmStockMapper plasmStockMapper;
	@Autowired
	private ExceptionCollectionsMapper  exceptionCollectionsMapper;
	
	Logger logger = Logger.getLogger(Sync2JingyingImpl.class);

	@Override
	public void doProviderBaseInfoExec() throws Exception {

		Date now = new Date();
		String nowStr = DateTools.getInstance().dateFormat(now, "yyyy-MM-dd HH:mm:ss");
		String nowStrZero = DateTools.getInstance().dateFormat(now, "yyyy-MM-dd");

		GJZXX gjzxx = new GJZXX();
		gjzxx.setModify_time(nowStr);
		DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
		List<GJZXX> gjzs = GJZXXMapper.getGJZXX(gjzxx);

		logger.info("待同步的供浆者信息 记录数=" + gjzs.size());

		List<GJZXX> successGjz = new ArrayList<GJZXX>();// 用来存储同步到精英系统成功了的浆员，然后再更新佳颖数据库中的同步状态

		for (GJZXX gjz : gjzs) {

			try {
				logger.info("同步的供浆者【" + gjz.getCARDID() + "-" + gjz.getXM() + "】开始~~~");

				ProviderBaseInfo provider = new ProviderBaseInfo();
				provider.setIDNo(gjz.getSFZ());
				DataSourceContextHolder.setDataSourceType(DataSourceConst.jingying);
				List<ProviderBaseInfo> baseInfoList = providerBaseInfoMapper.getProviderBaseInfo(provider);

				CardTable cardtable = new CardTable();

				if (baseInfoList != null && baseInfoList.size() == 1) {
					provider = baseInfoList.get(0);

					if (provider.getICNo() != null && provider.getICNo().length() > 0) {

					} else {
//						if ((!gjz.getCARDID().startsWith("R") && provider.getProviderNo().startsWith("R")) || (!provider.getProviderNo().startsWith("R") && ("".equals(provider.getICNo()) || provider.getICNo() == null))) {
						if (!gjz.getCARDID().startsWith("R")  && ("".equals(provider.getICNo()) || provider.getICNo() == null) || "0".equals(provider.getICNo())) {
							// 获取精英最大的IC卡号
							String maxIcNo = providerBaseInfoMapper.getMaxIcNo();

							int int_icno = 1;
							try {
								int_icno = Integer.parseInt(maxIcNo);
							} catch (Exception e) {
							}
							int_icno = int_icno + 1;

							String icno = NumberTools.getInstance().decimalFormat(int_icno, 10);
							// 保存精英IC卡使用状态
							cardtable.setICNo(Base64Utils.encode(icno));
							List<CardTable> cardList = cardTableMapper.getCardTable(cardtable);
							if (cardList != null && cardList.size() > 0) {
								cardtable = cardList.get(0);
								cardtable.setState("1");
							}
							provider.setICNo(icno);// IC卡号

							logger.info("写精英的日志：发卡  start");

							String nurse = gjz.getCREATENURSE();

							userSet userSet = new userSet();
							userSet.setPERSONID(nurse);
							DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
							List<userSet> userList = userSetMapper.selectByuserSet(userSet);

							String optionerName = "";// 操作员
							if (userList != null && userList.size() > 0) {
								optionerName = userList.get(0).getPERSONNAME();
							}

							int worker = 0;
							if (nurse != null && !"".equals(nurse) && nurse.length() > 3) {
								if (NumberTools.getInstance().isNumeric2(nurse.substring(3))) {
									worker = Integer.parseInt(nurse.substring(3));
								}
							}

							try {

								SystemLogJiaying sysLog = new SystemLogJiaying();
								sysLog.setModeName("发卡");
								String optionInfo = "操作员：" + optionerName + "把新浆员<" + gjz.getXM() + "> 编号为："
										+ provider.getProviderNo() + "改成编号为：" + gjz.getCARDID() + "；并发卡号为：" + icno;
								sysLog.setOptioninfo(optionInfo);
								sysLog.setOptionter(worker + "");
								sysLog.setOptionterdate(nowStr);
								sysLog.setOptdate(nowStr);
								sysLog.setOptdate(nowStrZero);
								sysLog.setSynDate(nowStrZero);
								sysLog.setModify_time(nowStr);
								sysLog.setDelbat("0");
								DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
								systemLogJiayingMapper.addSystemLog(sysLog);

							} catch (Exception e) {
								logger.info("写精英的日志：发卡  异常：" + e.getMessage());
							}
							logger.info("写精英的日志：发卡  end");

						}
					}

				} else {
					provider.setSFFZ("0");
					provider.setOrg_id("0");
					provider.setUpdate_flag("2");
					provider.setUpdate_date("1900-01-01 00:00:00");
					provider.setWeb_flag("-1");
					provider.setUppic_flag("0");
					provider.setZw_downflag("0");
					provider.setAvalue("0");
					provider.setOrg_id_SW("0");
					provider.setUpdate_flag_SW("2");
					provider.setUpdate_date_SW("1900-01-01 00:00:00");
					provider.setWeb_flag_SW("-1");
					provider.setOrg_id_QT("0");
					provider.setUpdate_flag_QT("0");
					provider.setUpdate_date_QT("1900-01-01 00:00:00");
					provider.setWeb_flag_QT("-1");
					provider.setUppic_flag_sw("0");
					provider.setUppic_flag_qt("0");
					provider.setZw_downflag_sw("0");
					provider.setZw_downflag_qt("0");
					provider.setTrafficFee("0");
					provider.setCJCS_0912("0");
					provider.setCJCS_1001("0");
					provider.setCJCS_1002("0");
					provider.setUpdate_flag_bm("0");
					provider.setJSRID("0");
					provider.setNLXX("0");
					provider.setSend_dx("否");
					provider.setPH_IFVIP("0");

					provider.setOLdNewRedatebz("1");
				}

				provider.setIDNo(gjz.getSFZ());
				provider.setName(gjz.getXM());
				if (gjz.getXMID().equals("1")) {
					provider.setSex("M");
				} else if (gjz.getXMID().equals("2")) {
					provider.setSex("F");
				}

				provider.setProviderNo(gjz.getCARDID());

				if (provider.getIDCardPhoto() != null && provider.getIDCardPhoto().length > 0) {
				} else {
					if (gjz.getIDCARDPHOTO() != null && gjz.getIDCARDPHOTO().length > 0) {

						byte[] photo = getByte(gjz.getPHOTO());
						byte[] Idcardphoto = getByte(gjz.getIDCARDPHOTO());
						byte[] Idcardphoto1 = getByte(gjz.getIDCARDPHOTO1());

						provider.setPhoto(photo);
						provider.setIDCardPhoto(Idcardphoto);
						provider.setIDCardPhotoBlack(Idcardphoto1);
					}
				}

				provider.setBirthDay(gjz.getBIRTHDAY());
				provider.setAddress(gjz.getSFZDZ());
				provider.setTel(gjz.getPHONE());
				provider.setProviderState(gjz.getGJZSTATE());

				String fileDate = DateTools.getInstance().dateFormat(
						DateTools.getInstance().stringFormat(gjz.getCREATERQ(), "yyyy-MM-dd"), "yyyy-MM-dd HH:mm:ss");
				provider.setFileDate(fileDate);

				provider.setTimes(gjz.getZJSJCS());
				provider.setRegistDate(fileDate);
				if (gjz.getREFUSEDATE() != null &&  !"".equals(gjz.getREFUSEDATE())) {
					String refuseDate = DateTools.getInstance().dateFormat(
							DateTools.getInstance().stringFormat(gjz.getREFUSEDATE(), "yyyy-MM-dd"),
							"yyyy-MM-dd HH:mm:ss");
					provider.setRefuseDate(refuseDate);
				} else {
					provider.setRefuseDate("1900-01-01 00:00:00");
				}
				provider.setProviderType("1");
				provider.setRefuseReason(gjz.getREFUSENOTE());

				provider.setNowAddress(gjz.getDZ());
				provider.setNation(gjz.getNATION());// 民族需要添加字段到我们数据库
				provider.setSFZ_DQ(gjz.getSFZYXQ());

				int worker = 0;
				if(gjz.getCREATENURSE() != null){
					if (NumberTools.getInstance().isNumeric2(gjz.getCREATENURSE().substring(3))) {
						worker = Integer.parseInt(gjz.getCREATENURSE().substring(3));
					}
				}

				provider.setRegister(worker + "");

				// 登记号
				Date createrq = DateTools.getInstance().stringFormat(gjz.getCREATERQ(), "yyyy-MM-dd");
				String regTimeId = DateTools.getInstance().dateFormat(createrq, "yyyyMMdd");

				Sfproviderreg register = new Sfproviderreg();
				register.setIDNO(gjz.getSFZ());
				register.setREGTIMEID(Integer.parseInt(regTimeId));
				DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
				List<Sfproviderreg> registerList = sfproviderregMapper.selectByCondition(register);
				if (registerList != null && registerList.size() > 0) {
					String regno = registerList.get(0).getREGISTERNO();
					provider.setSmallNo(regno);
				}
				provider.setBloodType(gjz.getXXID());
			//同步建档，在登记时指纹打钩的
                provider.setFingerMark("1");
				// 同步指纹信息
				DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
				List<GjzZwTable> gzwList = gjzZwTableMapper.selectZwById(gjz.getID());
				if (gzwList != null) {
					for (GjzZwTable gzw : gzwList) {
						DataSourceContextHolder.setDataSourceType(DataSourceConst.jingying);
						List<ProviderZwTable> zwList = providerZwTableMapper.selectZw(gjz.getCARDID(), gzw.getCode());
						ProviderZwTable zw = null;
						if (zwList != null && zwList.size() > 0) {
							zw = zwList.get(0);
						} else {
							zw = new ProviderZwTable();
						}
						zw.setCode(gzw.getCode());
						zw.setProviderno(gjz.getCARDID());
						zw.setZW(gzw.getZw());

						if(zw.getID() != null && !"".equals(zw.getID())){
							providerZwTableMapper.updateZw(zw);
						}else{
							providerZwTableMapper.saveZw(zw);
						}
						logger.info(
								"同步的供浆者【" + gjz.getCARDID() + "-" + gjz.getXM() + "】指纹 【" + gzw.getCode() + "】 结束~~~");
					}
				}

				DataSourceContextHolder.setDataSourceType(DataSourceConst.jingying);
				if (cardtable.getICNo() != null && !"".equals(cardtable.getICNo())) {
					cardTableMapper.updateCardTable(cardtable);
				}
				if (provider.getBaseNo() != null && !"".equals(provider.getBaseNo())) {
					providerBaseInfoMapper.updateProviderBaseInfo(provider);
				} else {
					providerBaseInfoMapper.addProviderBaseInfo(provider);
				}
				successGjz.add(gjz);
				logger.info("同步的供浆者【" + gjz.getCARDID() + "-" + gjz.getXM() + "】结束~~~");
			} catch (Exception e) {
				e.printStackTrace();
				logger.info("同步的供浆者【" + gjz.getCARDID() + "-" + gjz.getXM() + "】异常，异常信息：" + e.getMessage());
			}
		}

		// 更新佳颖数据库中的同步时间
		DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
		for (GJZXX gjz : successGjz) {
			try {
				logger.info("更新浆员信息表 GJZXX 中的【" + gjz.getCARDID() + "-" + gjz.getXM() + "】的同步状态开始~~~");

				gjz.setSynDate(nowStr);
				// 这里将同步时间修改为现在
				GJZXXMapper.updateGJZXX(gjz);
				logger.info("更新浆员信息表 GJZXX 中的【" + gjz.getCARDID() + "-" + gjz.getXM() + "】的同步状态结束~~~");
			} catch (Exception e) {
				e.printStackTrace();
				logger.info(
						"更新浆员信息表 GJZXX 中的【" + gjz.getCARDID() + "-" + gjz.getXM() + "】的同步状态异常，异常信息：" + e.getMessage());
			}
		}

	}

	@Override
	public void doProviderRegisterExec() throws Exception {

		Date now = new Date();
		String nowStr = DateTools.getInstance().dateFormat(now, "yyyy-MM-dd HH:mm:ss");

		Sfproviderreg register = new Sfproviderreg();
		register.setMODIFY_TIME(nowStr);
		DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
		List<Sfproviderreg> registerList = sfproviderregMapper.selectByCondition(register);
		logger.info("待同步的供浆者登记信息 记录数=" + registerList.size());

		List<Sfproviderreg> successReg = new ArrayList<Sfproviderreg>();

		for (Sfproviderreg reg : registerList) {

			try {
				logger.info("同步的供浆者【" + reg.getPROVIDERNO() + "】登记信息开始~~~");
				DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
				GJZXX gjz = new GJZXX();
				gjz.setID(reg.getGJZID() + "");

				List<GJZXX> gjzList = GJZXXMapper.getGJZXX(gjz);
				if (gjzList != null && gjzList.size() > 0) {
					gjz = gjzList.get(0);
				} else {
					logger.info("同步的供浆者【" + reg.getPROVIDERNO() + "】登记信息失败，没有找到供浆者基本信息 ~~~");
					continue;
				}

				ProviderRegister providerRegister = new ProviderRegister();
				providerRegister.setSmallNo(reg.getREGISTERNO());
				DataSourceContextHolder.setDataSourceType(DataSourceConst.jingying);
				List<ProviderRegister> regList = providerRegisterMapper.getProviderRegister(providerRegister);
				if (regList != null && regList.size() > 0) {
					providerRegister = regList.get(0);
				} else {
					logger.info("同步的供浆者【" + reg.getPROVIDERNO() + "】登记信息失败，没有找到供浆者在精英的登记信息 ~~~");
					continue;
				}

				Registerteminfo temp = new Registerteminfo();
				temp.setSmallNo(reg.getREGISTERNO());

				List<Registerteminfo> regTempList = registerteminfoMapper.selectRegisterteminfo(temp);

				boolean flag = false;
				if (regTempList != null && regTempList.size() > 0) {
					temp = regTempList.get(0);
					flag = true;
				}

				temp.setProviderno(gjz.getCARDID());
				temp.setRegistDate(DateTools.getInstance().dateFormatZero(reg.getREGTIME()));
				temp.setSmallNo(reg.getREGISTERNO());

				providerRegister.setProviderNo(gjz.getCARDID());

				providerRegisterMapper.updateProviderRegister(providerRegister);
				if (flag) {
					registerteminfoMapper.updateRegisterteminfo(temp);
				} else {
					registerteminfoMapper.saveRegisterteminfo(temp);
				}

				successReg.add(reg);
				logger.info("同步的供浆者【" + reg.getPROVIDERNO() + "】登记信息结束~~~");
			} catch (Exception e) {
				logger.info("同步的供浆者【" + reg.getPROVIDERNO() + "】登记信息异常，异常信息：" + e.getMessage());
				e.printStackTrace();
			}
		}

		// 更新佳颖数据库中的同步时间
		DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
		for (Sfproviderreg reg : successReg) {
			try {
				logger.info("更新同步的供浆者【" + reg.getPROVIDERNO() + "】登记信息的同步状态开始~~~");

				reg.setSYNDATE(nowStr);
				sfproviderregMapper.updateSfproviderreg(reg);
				logger.info("更新同步的供浆者【" + reg.getPROVIDERNO() + "】登记信息的同步状态结束~~~");
			} catch (Exception e) {
				e.printStackTrace();
				logger.info("更新供浆者【" + reg.getPROVIDERNO() + "】登记信息的同步状态异常，异常信息：" + e.getMessage());
			}
		}

	}

	@Override
	public void doBodyCheckExec() throws Exception {

		Date now = new Date();
		String nowStr = DateTools.getInstance().dateFormat(now, "yyyy-MM-dd HH:mm:ss");

		GJZBodyCheck gjzBodyCheck = new GJZBodyCheck();
		gjzBodyCheck.setMODIFY_TIME(nowStr);
		DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
		List<GJZBodyCheck> bodyCheckList = GJZBodyCheckMapper.selectByBodyCheck(gjzBodyCheck);

		logger.info("待同步的供浆者体检信息 记录数=" + bodyCheckList.size());

		List<GJZBodyCheck> successBodyCheck = new ArrayList<GJZBodyCheck>();

		for (GJZBodyCheck gbc : bodyCheckList) {

			try {
				logger.info("同步的供浆者【" + gbc.getGJZID() + "】体检信息开始~~~");

				String bcDate = DateTools.getInstance().dateFormatZero(gbc.getJSSJ());
				DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
				GJZXX gjz = new GJZXX();
				gjz.setID(gbc.getGJZID());
				List<GJZXX> gjzList = GJZXXMapper.getGJZXX(gjz);
				if (gjzList != null && gjzList.size() > 0) {
					gjz = gjzList.get(0);
				} else {
					logger.info("同步的供浆者【" + gbc.getGJZID() + "】体检信息失败，没有找到供浆者基本信息 ~~~");
					continue;
				}
				DataSourceContextHolder.setDataSourceType(DataSourceConst.jingying);
				ProviderRegister providerRegister = new ProviderRegister();
				providerRegister.setSmallNo(gbc.getDJH());
				List<ProviderRegister> regList = providerRegisterMapper.getProviderRegister(providerRegister);
				if (regList != null && regList.size() > 0) {
					providerRegister = regList.get(0);
				} else {
					logger.info("同步的供浆者【" + gbc.getGJZID() + "】体检信息失败，没有找到供浆者在精英的登记信息 ~~~");
					continue;
				}

				BodyCheckRecord tbc = new BodyCheckRecord();
				tbc.setIDNo(gjz.getSFZ());
				tbc.setBodyCheckDate(bcDate);

				List<BodyCheckRecord> tbcList = bodyCheckRecordMapper.getBodyCheckRecord(tbc);

				if (tbcList != null && tbcList.size() > 0) {
					tbc = tbcList.get(0);
				} else {
					tbc.setIDNo(gjz.getSFZ());

					tbc.setSmallNo(gbc.getDJH());
					tbc.setBodyCheckDate(DateTools.getInstance().dateFormatZero(gbc.getJSSJ()));
					if (gjz.getCARDID().indexOf("R") >= 0) {
						tbc.setIfx("1");
					} else {
						tbc.setIfx("0");
					}
					tbc.setTj_find("是");// 健康征询
					tbc.setIF_GDJY(providerRegister.getIF_GDJY());// 是否固定奖员
					tbc.setIsAuditing("0");
					tbc.setAssessor("0");
					tbc.setOrg_id("0");
					tbc.setUpdate_flag("1");
					tbc.setUpdate_date(DateTools.getInstance().dateFormat(new Date(0L), "yyyy-MM-dd HH:mm:ss"));
					tbc.setWeb_flag("-1");
					tbc.setOrg_id_SW("0");
					tbc.setUpdate_flag_SW("1");
					tbc.setUpdate_date_SW(DateTools.getInstance().dateFormat(new Date(0L), "yyyy-MM-dd HH:mm:ss"));
					tbc.setWeb_flag_SW("-1");
					tbc.setOrg_id_QT("0");
					tbc.setUpdate_flag_QT("1");
					tbc.setUpdate_date_QT(DateTools.getInstance().dateFormat(new Date(0L), "yyyy-MM-dd HH:mm:ss"));
					tbc.setWeb_flag_QT("-1");
				}
				tbc.setProviderNo(gjz.getCARDID());
				tbc.setRegisterNo(providerRegister.getRegisterNo());

				int worker = 0;
				if (NumberTools.getInstance().isNumeric2(gbc.getASSESSOR().substring(3))) {
					worker = Integer.parseInt(gbc.getASSESSOR().substring(3));
				}
				tbc.setBodyCheckWorker(worker + "");// ID前三位必须是字母
				tbc.setAvoirdupois(gbc.getTZ());
				tbc.setAnimalHeat(gbc.getTW());
				tbc.setPulse(gbc.getMB());
				tbc.setBloodPressure(gbc.getXYD() + "/" + gbc.getXYG());

				tbc.setXB(gbc.getXBZT() == 0 ? "合格" : "不合格");
				tbc.setFB(gbc.getFBZT() == 0 ? "合格" : "不合格");
				tbc.setPF(gbc.getPFZT() == 0 ? "合格" : "不合格");
				tbc.setWG(gbc.getWGZT() == 0 ? "合格" : "不合格");
				tbc.setSZ(gbc.getSZZT() == 0 ? "合格" : "不合格");
				
				tbc.setHeart("1");
				tbc.setLung("1");
				tbc.setLiver("1");
				tbc.setSpleen("1");

				// String result = "";
				if (gbc.getHJJG() == 1) {
					providerRegister.setIsBodyPass("1");
					tbc.setBodyCheckResult("1");
					// result = "合格";
				} else {
					providerRegister.setIsBodyPass("0");
					tbc.setBodyCheckResult("0");
					// result = "不合格";
				}

				if (tbc.getBodyCheckNo() != null && !"".equals(tbc.getBodyCheckNo())) {
					bodyCheckRecordMapper.updateBodyCheckRecord(tbc);
				} else {
					bodyCheckRecordMapper.addBodyCheckRecord(tbc);
				}

				providerRegister.setIsOrder("1");// 让其状态到 采浆验证的 未验证人员队列中去
				providerRegisterMapper.updateProviderRegister(providerRegister);

				successBodyCheck.add(gbc);

				logger.info("同步的供浆者【" + gbc.getGJZID() + "】体检信息结束~~~");
			} catch (Exception e) {
				e.printStackTrace();
				logger.info("同步的供浆者【" + gbc.getGJZID() + "】体检信息异常：" + e.getMessage());
			}

		}
		DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
		// 更新佳颖数据库中的同步状态
		for (GJZBodyCheck gbc : successBodyCheck) {
			try {
				logger.info("更新浆员体检表 gjz_bodycheck 中的【" + gbc.getGJZID() + "-" + gbc.getDJH() + "】的同步状态开始~~~");

				// 这里将同步的状态改为已同步
				gbc.setSYNDATE(nowStr);
				GJZBodyCheckMapper.updateGJZBodyCheck(gbc);
				logger.info("更新浆员体检表 gjz_bodycheck 中的【" + gbc.getGJZID() + "-" + gbc.getDJH() + "】的同步状态结束~~~");
			} catch (Exception e) {
				e.printStackTrace();
				logger.info("更新浆员体检表 gjz_bodycheck 中的【" + gbc.getGJZID() + "-" + gbc.getDJH() + "】的同步状态异常，异常信息："
						+ e.getMessage());
			}
		}

	}

	@Override
	public void doAllotExec() throws Exception {

		Date now = new Date();
		String nowStr = DateTools.getInstance().dateFormat(now, "yyyy-MM-dd HH:mm:ss");
		String today = DateTools.getInstance().dateFormatZero(nowStr);

		distribution allt = new distribution();
		allt.setMODIFY_TIME(nowStr);
		DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
		List<distribution> alls = distributionMapper.selectByDistribution(allt);
		List<distribution> successAllt = new ArrayList<distribution>();

		logger.info("待同步的供浆者分配信息 记录数=" + alls.size());
		for (distribution all : alls) {
			try {
				logger.info("同步的供浆者【" + all.getGJZID() + "】分配信息开始~~~");
				DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
				GJZXX gjz = new GJZXX();
				gjz.setID(all.getGJZID() + "");

				List<GJZXX> gjzList = GJZXXMapper.getGJZXX(gjz);
				if (gjzList != null && gjzList.size() > 0) {
					gjz = gjzList.get(0);
				} else {
					logger.info("同步的供浆者【" + all.getGJZID() + "】分配信息失败，没有找到供浆者基本信息 ~~~");
					continue;
				}

				ProviderRegister providerRegister = new ProviderRegister();
				providerRegister.setSmallNo(all.getREGCODE());
				DataSourceContextHolder.setDataSourceType(DataSourceConst.jingying);
				List<ProviderRegister> regList = providerRegisterMapper.getProviderRegister(providerRegister);
				if (regList != null && regList.size() > 0) {
					providerRegister = regList.get(0);
				} else {
					logger.info("同步的供浆者【" + all.getJYKH() + "】分配信息失败，没有找到供浆者在精英的登记信息 ~~~");
					continue;
				}

				CollectionRecord cRecord = new CollectionRecord();
				cRecord.setProviderNo(all.getJYKH());
				cRecord.setCollectionDate(today);
				// 回写待采浆信息

				List<CollectionRecord> tcs = collectionRecordMapper.getCollectionRecord(cRecord);
				if (tcs != null && tcs.size() > 0) {
					cRecord = tcs.get(0);
				} else {
					cRecord.setCollectionDate(today);
					cRecord.setIsCollection("0");
					cRecord.setCollectionWorker("0");// 护士ID
					cRecord.setPlasmaGross("0");
					cRecord.setMachineStatus("1");
					cRecord.setCollectionInstance("0");// 采浆量是否足够
					cRecord.setCollectionResult("0");
					cRecord.setIsAuditing("1");
					cRecord.setRemark("");
					cRecord.setIsAuditing("0");
					cRecord.setAssessor("0");
					cRecord.setAssayNo("0");

					String d = DateTools.getInstance().dateFormat(new Date(0L), "yyyy-MM-dd");
					cRecord.setOrg_id("0");
					cRecord.setUpdate_flag("2");
					cRecord.setUpdate_date(d);
					cRecord.setWeb_flag("-1");

					cRecord.setOrg_id_SW("0");
					cRecord.setUpdate_flag_SW("2");
					cRecord.setUpdate_date_SW(d);
					cRecord.setWeb_flag_SW("-1");

					cRecord.setOrg_id_QT("0");
					cRecord.setUpdate_flag_QT("2");
					cRecord.setUpdate_date_QT(d);
					cRecord.setWeb_flag_QT("-1");

					cRecord.setIDNo(gjz.getSFZ());
					cRecord.setProviderNo(gjz.getCARDID());
					cRecord.setSmallNo(all.getREGCODE());
					cRecord.setCollectiondate_info(nowStr);

					cRecord.setIF_GDJY(providerRegister.getIF_GDJY());

					// 修改精英登记信息
					providerRegister.setIsShout("1");
					int shouter = 0;
					if (all.getCREATENURSE() != null && !"".equals(all.getCREATENURSE())) {
						if (all.getCREATENURSE().startsWith("mxz")) {
							try {
								shouter = Integer.parseInt(all.getCREATENURSE().substring(3));
							} catch (Exception e) {
							}
						}
					}
					providerRegister.setShouter(shouter + "");
					providerRegister.setShoutdate(today);

					DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
					// 血清电泳
					GJZXQDYQD dy = new GJZXQDYQD();
					dy.setGJZID(gjz.getID());
					dy.setXQDATE(today);
					List<GJZXQDYQD> dyList = GJZXQDYQDMapper.selectXXDY(dy);

					if (dyList != null && dyList.size() > 0) {
						dy = dyList.get(0);

						AssayXQDY jinyinxqdy = new AssayXQDY();
						jinyinxqdy.setProviderNo(gjz.getCARDID());
						jinyinxqdy.setLastXQDYdate(today);
						jinyinxqdy.setSmallno(providerRegister.getSmallNo());
						DataSourceContextHolder.setDataSourceType(DataSourceConst.jingying);
						List<AssayXQDY> assayXQDY = assayXQDYMapper.getAssayXQDY(jinyinxqdy);
						if (assayXQDY != null && assayXQDY.size() > 0) {

						} else {
							String nullDate = DateTools.getInstance().dateFormatZero("1900-01-01 00:00:00");

							jinyinxqdy.setProviderNo(gjz.getCARDID());
							jinyinxqdy.setSmallno(providerRegister.getSmallNo());

							jinyinxqdy.setXQDYPH("302D" + dy.getID());
							jinyinxqdy.setXQDYXH("" + dy.getCIDX());
							jinyinxqdy.setLastXQDYdate(today);
							
							jinyinxqdy.setOrg_id("0");
							jinyinxqdy.setUpdate_flag("1");
							jinyinxqdy.setUpdate_date(nullDate);
							jinyinxqdy.setWeb_flag("-1");
							jinyinxqdy.setOrg_id_SW("0");
							jinyinxqdy.setUpdate_flag_SW("1");
							jinyinxqdy.setUpdate_date_SW(nullDate);
							jinyinxqdy.setWeb_flag_SW("-1");
							jinyinxqdy.setOrg_id_QT("0");
							jinyinxqdy.setUpdate_flag_QT("1");
							jinyinxqdy.setUpdate_date_QT(nullDate);
							jinyinxqdy.setWeb_flag_QT("-1");

							jinyinxqdy.setLastXQDYAssayer(null);
							jinyinxqdy.setBDB(null);
							jinyinxqdy.setTuPu(null);
							jinyinxqdy.setDYDW(null);
							jinyinxqdy.setDYBZ(null);
							jinyinxqdy.setCZSJ(today);

							assayXQDYMapper.addAssayXQDY(jinyinxqdy);
						}

					}
					DataSourceContextHolder.setDataSourceType(DataSourceConst.jingying);
					if (cRecord.getCollectionNo() != null && !"".equals(cRecord.getCollectionNo())) {
						collectionRecordMapper.updateCollectionRecord(cRecord);
					} else {
						collectionRecordMapper.addCollectionRecord(cRecord);
					}
					providerRegisterMapper.updateProviderRegister(providerRegister);
				}

				successAllt.add(all);

				logger.info("同步的供浆者【" + all.getGJZID() + "】分配信息结束~~~");
			} catch (Exception e) {
				e.printStackTrace();
				logger.info("同步的供浆者【" + all.getGJZID() + "】分配信息异常：" + e.getMessage());
			}
		}
		DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
		for (distribution all : successAllt) {
			try {
				logger.info("更新浆员分配表 GJZ_ALLOT 中的【" + all.getGJZID() + "-" + all.getREGCODE() + "】的同步状态开始~~~");

				all.setSYNDATE(nowStr);
				distributionMapper.updateDistribution(all);
				logger.info("更新浆员分配表 GJZ_ALLOT 中的【" + all.getGJZID() + "-" + all.getREGCODE() + "】的同步状态结束~~~");
			} catch (Exception e) {
				e.printStackTrace();
				logger.info("更新浆员分配表 GJZ_ALLOT 中的【" + all.getGJZID() + "-" + all.getREGCODE() + "】的同步状态异常，异常信息："
						+ e.getMessage());
			}
		}

	}

	@Override
	public void doSampleCollectionExec() throws Exception {

		Date now = new Date();
		String nowStr = DateTools.getInstance().dateFormat(now, "yyyy-MM-dd HH:mm:ss");
		String nowZero = DateTools.getInstance().dateFormatZero(nowStr);
		
		GJZ_Sample_collection gSample = new GJZ_Sample_collection();
		gSample.setMODIFY_TIME(nowStr);
		DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
		List<GJZ_Sample_collection> scList = GJZ_Sample_CollectionMapper.selectBySample(gSample);

		List<GJZ_Sample_collection> successSample = new ArrayList<GJZ_Sample_collection>();

		logger.info("待同步的供浆小样采集 记录数=" + scList.size());

		for (GJZ_Sample_collection gsc : scList) {
			try {
				logger.info("同步小样采集信息【" + gsc.getXM() + "-" + gsc.getSMALLNO() + "】开始~~~");
				DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
				GJZXX gjz = new GJZXX();
				gjz.setID(gsc.getGJZID());
				List<GJZXX> gjzList = GJZXXMapper.getGJZXX(gjz);
				if (gjzList != null && gjzList.size() > 0) {
					gjz = gjzList.get(0);
				} else {
					logger.info("同步的供浆者【" + gsc.getGJZID() + "】小样采集信息失败，没有找到供浆者基本信息 ~~~");
					continue;
				}
				DataSourceContextHolder.setDataSourceType(DataSourceConst.jingying);
				ProviderRegister providerRegister = new ProviderRegister();
				providerRegister.setRegistDate(nowZero);
				providerRegister.setIDNo(gjz.getSFZ());
				List<ProviderRegister> regList = providerRegisterMapper.getProviderRegister(providerRegister);
				if (regList != null && regList.size() > 0) {
					providerRegister = regList.get(0);
				} else {
					logger.info("同步的供浆者【" + gsc.getGJZID() + "】小样采集信息失败，没有找到供浆者在精英的登记信息 ~~~");
					continue;
				}

				AssayRecord tr = new AssayRecord();
				tr.setIDNo(gjz.getSFZ());
				tr.setXYH_SmallNo(gsc.getSMALLNO());

				List<AssayRecord> trs = assayRecordMapper.getAssayRecord(tr);

				if (trs != null && trs.size() > 0) {
					tr = trs.get(0);
				} else {

					logger.info("新建小样采集信息");
					tr.setBodyCheckNo("0");
					tr.setIDNo(gsc.getSFZ());
					tr.setProviderNo(gjz.getCARDID());

					tr.setSmallNo(providerRegister.getSmallNo());// 登记号
					tr.setAssayWorker("0");
					tr.setIsRepeat("0");
					tr.setTempletNo("0");
					tr.setAssayResult("0");
					tr.setIsAuditing("0");
					tr.setAssessor("0");
					tr.setOrg_id("0");
					tr.setUpdate_flag("1");
					tr.setUpdate_date(DateTools.getInstance().dateFormat(new Date(0L), "yyyy-MM-dd HH:mm:ss"));
					tr.setUpdate_flag("-1");
					tr.setOrg_id_SW("0");
					tr.setUpdate_flag_SW("2");
					tr.setUpdate_date_SW(DateTools.getInstance().dateFormat(new Date(0L), "yyyy-MM-dd HH:mm:ss"));
					tr.setWeb_flag_SW("-1");
					tr.setOrg_id_QT("0");
					tr.setUpdate_flag_QT("2");
					tr.setUpdate_date_QT(DateTools.getInstance().dateFormat(new Date(0L), "yyyy-MM-dd HH:mm:ss"));
					tr.setWeb_flag_QT("-1");

					tr.setIF_GDJY("0");
					tr.setIfLST("1");
					if (gjz.getCARDID().startsWith("R")) {
						tr.setIfx("1");
					} else {
						tr.setIfx("0");
					}
				}

				tr.setXYH_SmallNo(gsc.getSMALLNO());// 小样号
				tr.setAssayDate(DateTools.getInstance().dateFormatZero(gsc.getJLSJ()));
				int worker = 30;
				String nurseid = gsc.getCREATENURSE();
				if (nurseid != null && !"".equals(nurseid) && nurseid.length() > 3) {
					if (NumberTools.getInstance().isNumeric2(nurseid.substring(3))) {
						worker = Integer.parseInt(nurseid.substring(3));
					}
				}
				tr.setLSTWERKER(worker + "");
				tr.setAssayBBDate(DateTools.getInstance().dateFormatZero(gsc.getJLSJ()));
				tr.setLSTdate(DateTools.getInstance().dateFormatZero(gsc.getJLSJ()));

				// 写入assayRecordRegister表的数据
				AssayRecordRegister trr = new AssayRecordRegister();
				trr.setProviderno(gjz.getCARDID());
				trr.setxYH_SmallNo(gsc.getSMALLNO());

				List<AssayRecordRegister> trrs = assayRecordRegisterMapper.getAssayRecordRegister(trr);

				boolean flag = false;
				if (trrs != null && trrs.size() > 0) {
					trr = trrs.get(0);
					flag = true;
				}

				trr.setAssayDate(DateTools.getInstance().dateFormatZero(gsc.getJLSJ()));
				trr.setProviderno(gjz.getCARDID());
				trr.setSmallno(tr.getSmallNo());
				trr.setxYH_SmallNo(tr.getXYH_SmallNo());

				// 回写登记信息
				providerRegister.setIsValidate("1");
				providerRegister.setValidater(worker + "");
				providerRegister.setXYH_SmallNo(tr.getXYH_SmallNo());
				providerRegister.setYyisvalidate("1");
				providerRegisterMapper.updateProviderRegister(providerRegister);

				if (flag) {
					assayRecordRegisterMapper.updateAssayRecordRegister(trr);
				} else {
					assayRecordRegisterMapper.addAssayRecordRegister(trr);
				}

				if (tr.getAssayNo() != null && !"".equals(tr.getAssayNo())) {
					assayRecordMapper.updateAssayRecord(tr);
				} else {
					assayRecordMapper.addAssayRecord(tr);
				}

				successSample.add(gsc);
				logger.info("同步小样采集信息【" + gsc.getXM() + "-" + gsc.getSMALLNO() + "】结束~~~");
			} catch (Exception e) {
				e.printStackTrace();
				logger.info("同步小样采集信息【" + gsc.getXM() + "-" + gsc.getSMALLNO() + "】异常，异常信息：" + e.getMessage());
			}

		}
		DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
		for (GJZ_Sample_collection gsc : successSample) {
			try {
				logger.info(
						"更新小样采集信息表 GJZ_SAMPLE_COLLECTION 中的【" + gsc.getXM() + "-" + gsc.getSMALLNO() + "】的同步状态开始~~~");

				gsc.setSYNDATE(nowStr);
				GJZ_Sample_CollectionMapper.updateSample(gsc);
				logger.info(
						"更新小样采集信息表 GJZ_SAMPLE_COLLECTION 中的【" + gsc.getXM() + "-" + gsc.getSMALLNO() + "】的同步状态结束~~~");
			} catch (Exception e) {
				e.printStackTrace();
				logger.info("更新小样采集信息表 GJZ_SAMPLE_COLLECTION 中的【" + gsc.getXM() + "-" + gsc.getSMALLNO()
						+ "】的同步状态异常，异常信息：" + e.getMessage());
			}
		}

	}

	@Override
	public void doAssayExec() throws Exception {

		Date now = new Date();
		String nowStr = DateTools.getInstance().dateFormat(now, "yyyy-MM-dd HH:mm:ss");
		DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
		GJZ_SAMPLE_ASSAY assay = new GJZ_SAMPLE_ASSAY();
		assay.setMODIFY_TIME(nowStr);
		List<GJZ_SAMPLE_ASSAY> aList = GJZ_Sample_ASSAYMapper.selectByAssay(assay);

		List<GJZ_SAMPLE_ASSAY> successAssay = new ArrayList<GJZ_SAMPLE_ASSAY>();

		logger.info("待同步的供浆化检 记录数=" + aList.size());

		for (GJZ_SAMPLE_ASSAY gsc : aList) {
			try {
				logger.info("同步化检信息【" + gsc.getGJZID() + "-" + gsc.getSMALLNO() + "】开始~~~");
				DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
				GJZXX gjz = new GJZXX();
				gjz.setID(gsc.getGJZID());
				List<GJZXX> gjzList = GJZXXMapper.getGJZXX(gjz);
				if (gjzList != null && gjzList.size() > 0) {
					gjz = gjzList.get(0);
				} else {
					logger.info("同步的供浆者【" + gsc.getGJZID() + "】化检信息失败，没有找到供浆者基本信息 ~~~");
					continue;
				}

				String jlkssj = gsc.getJLKSSJ();
				jlkssj = DateTools.getInstance().dateFormatZero(jlkssj);
				DataSourceContextHolder.setDataSourceType(DataSourceConst.jingying);
				ProviderRegister providerRegister = new ProviderRegister();
				providerRegister.setRegistDate(jlkssj);
				providerRegister.setIDNo(gjz.getSFZ());
				List<ProviderRegister> regList = providerRegisterMapper.getProviderRegister(providerRegister);
				if (regList != null && regList.size() > 0) {
					providerRegister = regList.get(0);
				} else {
					logger.info("同步的供浆者【" + gsc.getGJZID() + "】化检信息失败，没有找到供浆者在精英的登记信息 ~~~");
					continue;
				}

				AssayRecord tr = new AssayRecord();
				tr.setIDNo(gjz.getSFZ());
				tr.setXYH_SmallNo(gsc.getSMALLNO());

				List<AssayRecord> trs = assayRecordMapper.getAssayRecord(tr);

				if (trs != null && trs.size() > 0) {
					tr = trs.get(0);
				} else {
					tr.setIDNo(gjz.getSFZ());

					tr.setSmallNo(providerRegister.getSmallNo());// 登记号
					tr.setAssayWorker("0");
					tr.setIsRepeat("0");
					tr.setTempletNo("0");
					tr.setAssayResult("0");
					tr.setIsAuditing("0");
					tr.setAssessor("0");
					tr.setOrg_id("0");
					tr.setUpdate_flag("1");
					tr.setUpdate_date(DateTools.getInstance().dateFormat(new Date(0L), "yyyy-MM-dd HH:mm:ss"));
					tr.setUpdate_flag("-1");
					tr.setOrg_id_SW("0");
					tr.setUpdate_flag_SW("2");
					tr.setUpdate_date_SW(DateTools.getInstance().dateFormat(new Date(0L), "yyyy-MM-dd HH:mm:ss"));
					tr.setWeb_flag_SW("-1");
					tr.setOrg_id_QT("0");
					tr.setUpdate_flag_QT("2");
					tr.setUpdate_date_QT(DateTools.getInstance().dateFormat(new Date(0L), "yyyy-MM-dd HH:mm:ss"));
					tr.setWeb_flag_QT("-1");
					tr.setBodyCheckNo("0");

					tr.setIF_GDJY(providerRegister.getIF_GDJY());
					tr.setIfLST(providerRegister.getIfLST());
					if (gjz.getCARDID().startsWith("R")) {
						tr.setIfx("1");
					} else {
						tr.setIfx("0");
					}
				}

				tr.setXYH_SmallNo(gsc.getSMALLNO());

				int worker = 0;
				String nurseid = gsc.getHJJLR();
				if (nurseid != null && !"".equals(nurseid) && nurseid.length() > 3) {
					if (NumberTools.getInstance().isNumeric2(nurseid.substring(3))) {
						worker = Integer.parseInt(nurseid.substring(3));
					}
				}
				tr.setAssayWorker(worker + "");

				tr.setProviderNo(gjz.getCARDID());
				tr.setHBsAg(gsc.getHBSAG() + "");
				tr.setHCV(gsc.getKHCV() + "");

				String alt = gsc.getALT() + "";
				if ("1".equals(alt)) {
					alt = "≤40u";
				} else if ("2".equals(alt)) {
					alt = ">40u";
				} else if ("3".equals(alt)) {
					alt = "复检";
				} else if ("4".equals(alt)) {
					alt = "≤25u";
				} else if ("5".equals(alt)) {
					alt = ">25u";
				}
				tr.setALT(alt);

				tr.setHIV(gsc.getKHIV() + "");
				int xhdbhl = gsc.getXHDBHL();

				if (xhdbhl == 0) {
					xhdbhl = -1;
				}

				// 液面上/下
				if (1 == xhdbhl) {
					tr.setYMXia("1");
					tr.setLSTJG("≥120");
				} else if (3 == xhdbhl) {
					tr.setYMXia("1");
					tr.setLSTJG("≥110");
				} else if (2 == xhdbhl) {
					tr.setYMShang("1");
					tr.setLSTJG("<120");
				} else if (4 == xhdbhl) {
					tr.setYMShang("1");
					tr.setLSTJG("<110");
				}

				String proteide = null;
				if (gsc.getDBHL() != null && !"".equals(gsc.getDBHL())) {
					proteide = gsc.getDBHL();
				} else {
					proteide = gsc.getXHDBHL() + "";
				}
				if (proteide != null && !"".equals(proteide)) {
					tr.setProteide(proteide);
					if(proteide.length()>1){
						tr.setZSYKDZ(proteide.substring(0, 1) + "." + proteide.substring(1, 2));
					}
				}
				tr.setTempletNovar("检验");

				Integer hjjg = gsc.getHJJG();
				if (hjjg != null && 1 == hjjg) {
					tr.setDBZJG("合格");
				}

				tr.setLSTWERKER(worker + "");

				if (gsc.getQXBZ() == 0) {
					tr.setAllBlood("1");
				} else if (gsc.getQXBZ() == 1) {
					tr.setAllBlood("0");
				}
				tr.setSyphilis(gsc.getMD() + "");
				// String hjjg_ = "";
				if (gsc.getHJJG() == 1) {
					// hjjg_ = "合格";
					tr.setAssayResult("1");
					providerRegister.setIsAssayPass("1");
				} else {
					// hjjg_ = "不合格";
					tr.setAssayResult("0");
					providerRegister.setIsAssayPass("0");
				}
				// 修改精英化检记录
				providerRegister.setLSTWERKER(worker + "");
				providerRegister.setXYH_SmallNo(gsc.getSMALLNO());
				providerRegister.setLSTWERKER(worker + "");

				String date = gsc.getSMALLNO().substring(0, 8);// 小样化检的时间
				String date2 = DateTools.getInstance().dateFormatZero(date);
				tr.setAssayDate(date2);
				tr.setLSTdate(date2);
				tr.setAssayBBDate(date2);

				// 写入assayRecordRegister表的数据
				AssayRecordRegister trr = new AssayRecordRegister();
//				trr.setProviderno(gjz.getCARDID());
				trr.setxYH_SmallNo(gsc.getSMALLNO());

				List<AssayRecordRegister> trrs = assayRecordRegisterMapper.getAssayRecordRegister(trr);

				boolean flag = false;
				if (trrs != null && trrs.size() > 0) {
					trr = trrs.get(0);
					flag = true;
				}

				trr.setAssayDate(date2);
				trr.setProviderno(gjz.getCARDID());
				trr.setSmallno(tr.getSmallNo());
				trr.setxYH_SmallNo(tr.getXYH_SmallNo());

				if (flag) {
					assayRecordRegisterMapper.updateAssayRecordRegister(trr);
				} else {
					assayRecordRegisterMapper.addAssayRecordRegister(trr);
				}

				providerRegisterMapper.updateProviderRegister(providerRegister);
				if (tr.getAssayNo() != null && !"".equals(tr.getAssayNo())) {
					assayRecordMapper.updateAssayRecord(tr);
				} else {
					assayRecordMapper.addAssayRecord(tr);
				}

				successAssay.add(gsc);
				logger.info("同步化检信息【" + gsc.getGJZID() + "-" + gsc.getSMALLNO() + "】结束~~~");
			} catch (Exception e) {
				e.printStackTrace();
				logger.info("同步化检信息【" + gsc.getGJZID() + "-" + gsc.getSMALLNO() + "】异常，异常信息：" + e.getMessage());
			}

		}
		DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
		for (GJZ_SAMPLE_ASSAY gsc : successAssay) {
			try {
				logger.info(
						"更新化检信息表 GJZ_SAMPLE_COLLECTION 中的【" + gsc.getGJZID() + "-" + gsc.getSMALLNO() + "】的同步状态开始~~~");

				gsc.setSYNDATE(nowStr);
				GJZ_Sample_ASSAYMapper.updateAssay(gsc);
				logger.info(
						"更新化检信息表 GJZ_SAMPLE_COLLECTION 中的【" + gsc.getGJZID() + "-" + gsc.getSMALLNO() + "】的同步状态结束~~~");
			} catch (Exception e) {
				e.printStackTrace();
				logger.info("更新化检信息表 GJZ_SAMPLE_COLLECTION 中的【" + gsc.getGJZID() + "-" + gsc.getSMALLNO()
						+ "】的同步状态异常，异常信息：" + e.getMessage());
			}
		}

	}

	@Override
	public void doCollectionExec() throws Exception {
		Date now = new Date();
		String nowStr = DateTools.getInstance().dateFormat(now, "yyyy-MM-dd HH:mm:ss");

		Aphereses aphereses = new Aphereses();
		aphereses.setMODIFY_TIME(nowStr);
		DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
		List<Aphereses> apList = apheresesMapper.selectByCj(aphereses);

		logger.info("待同步的供浆者采浆信息 记录数=" + apList.size());

		List<Aphereses> successAp = new ArrayList<Aphereses>();

		String todaytime = DateTools.getInstance().dateFormat(now, "yyyy-MM-dd");

		for (Aphereses ap : apList) {

			try {
				logger.info("同步的供浆者【" + ap.getSFZ() + "】采浆信息开始~~~");
				DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
				GJZXX gjz = new GJZXX();
				gjz.setID(ap.getDONOR_ID());
				List<GJZXX> gjzList = GJZXXMapper.getGJZXX(gjz);
				if (gjzList != null && gjzList.size() > 0) {
					gjz = gjzList.get(0);
				} else {
					logger.info("同步的供浆者【" + ap.getDONOR_ID() + "】采浆信息失败，没有找到供浆者基本信息 ~~~");
					continue;
				}
				DataSourceContextHolder.setDataSourceType(DataSourceConst.jingying);
				ProviderRegister providerRegister = new ProviderRegister();
				providerRegister.setRegistDate(todaytime);
				providerRegister.setIDNo(gjz.getSFZ());
				List<ProviderRegister> regList = providerRegisterMapper.getProviderRegister(providerRegister);
				if (regList != null && regList.size() > 0) {
					providerRegister = regList.get(0);
				} else {
					logger.info("同步的供浆者【" + ap.getDONOR_ID() + "】采浆信息失败，没有找到供浆者在精英的登记信息 ~~~");
					continue;
				}


				// 精英采浆记录
				CollectionRecord cRecord = new CollectionRecord();
				cRecord.setProviderNo(gjz.getCARDID());
				cRecord.setCollectionDate(todaytime);
             //创建异常记录
				ExceptionCollections exceptionCollections=new ExceptionCollections();
				exceptionCollections.setProviderNo(gjz.getCARDID());
				exceptionCollections.setCollectionDate(todaytime);
				exceptionCollections.setMachineNo(ap.getMAC_ID());
				List<CollectionRecord> tcs = collectionRecordMapper.getCollectionRecord(cRecord);

				if (tcs != null && tcs.size() > 0) {
					cRecord = tcs.get(0);
				}
				
				String factoryPlasmaNo = cRecord.getFactoryPlasmaNo();//
				if(factoryPlasmaNo != null && !"".equals(factoryPlasmaNo)){
					//证明已经生成了耗材记录了，就不要重复使用耗材了
					cRecord.setIDNo(gjz.getSFZ());
					cRecord.setAssayNo("0");// 化检编号

					cRecord.setSmallNo(providerRegister.getSmallNo());
					cRecord.setProviderNo(gjz.getCARDID());

					cRecord.setCollectionDate(DateTools.getInstance().dateFormatZero(ap.getSTART_TIME()));
					int worker = 0;
					if (ap.getUSERID() != null && !"".equals(ap.getUSERID()) && ap.getUSERID().length() > 3) {
						if (NumberTools.getInstance().isNumeric2(ap.getUSERID().substring(3))) {
							worker = Integer.parseInt(ap.getUSERID().substring(3));
						}
					}
					cRecord.setIsCollection("1");
					cRecord.setCollectionWorker(worker + "");// 护士ID
					// cRecord.setPlasmano(pcode);//血浆编号
					cRecord.setIsAuditing("1");
					if (ap.getNUMS() >= 590) {
						cRecord.setPlasmaGross(600 + "");
					} else {
						cRecord.setPlasmaGross(ap.getNUMS() + "");
					}
					long runtime = ap.getCOLLTAKEN() / 60;
					if(runtime > 100){
						//大于100分钟
						exceptionCollections.setCycleTimes(String.valueOf(runtime));
						//如果得到的时间出现异常，那么自动生成一个基于 30 -- 50 之间的一个随机数 作为运行时间
						runtime = new Random().nextInt(50 - 30 + 1) + 30;
					}
					
					cRecord.setCycleTimes(String.valueOf(ap.getCYCLES()));
					cRecord.setRunTime(String.valueOf(runtime));
					cRecord.setAnticoagulant((int)ap.getANTI_NUMS() + "");
					cRecord.setBloodGross(ap.getTOTAL_NUMS() + "");
					
					if(cRecord.getPlasmaGross().equals("600")){
						if(runtime<20){
							exceptionCollections.setRuntime(String.valueOf(runtime));
							runtime=20;
							cRecord.setRunTime(String.valueOf(runtime));
						}
						
						if(ap.getANTI_NUMS()<60){
							exceptionCollections.setAnticoagulant(ap.getANTI_NUMS() +"");
							int anticoagulant=new Random().nextInt(10) +60;
							cRecord.setAnticoagulant(anticoagulant+ "");
						}
						if(ap.getTOTAL_NUMS()<1000){
							exceptionCollections.setBloodGross(ap.getTOTAL_NUMS()+""); 	
							int BloodGross=new Random().nextInt(10) +1100;
							cRecord.setBloodGross(BloodGross+"");
						}
						if(ap.getCYCLES()<2){
							exceptionCollections.setCycleTimes(ap.getCYCLES()+"");
							cRecord.setCycleTimes("2");
						}
					}
					
					
					

					// 机器信息
					cRecord.setMachineNo(ap.getMAC_ID());

				
					cRecord.setMachineStatus("1");
					if (ap.getNUMS() >= 590) {
						cRecord.setCollectionInstance("1");// 采浆量是否足够
					} else {
						cRecord.setCollectionInstance("0");// 采浆量是否足够
					}
					cRecord.setCJYZ("是");
					cRecord.setCJJX("ZXDC");
					cRecord.setRemark("");
					if (ap.getSFYCL() == 1) {
						cRecord.setCollectionResult("1");
					} else {
						cRecord.setCollectionResult("0");
					}

					cRecord.setIF_GDJY(providerRegister.getIF_GDJY());
					cRecord.setCollectiondate_info(nowStr);
					
					collectionRecordMapper.updateCollectionRecord(cRecord);
				}else{
					KHCSL hc = new KHCSL();
					hc.setNumber("0");
					hc.setMaterialNo("001");

					KHCSL knj = new KHCSL();
					knj.setNumber("0");
					knj.setMaterialNo("002");

					// 查找耗材和抗凝剂，按照入库的时间最早的查询
					List<KHCSL> hc_list01 = kHCSLMapper.getKHCSL(hc);
					List<KHCSL> hc_list02 = kHCSLMapper.getKHCSL(knj);

					if (hc_list01 != null && hc_list01.size() > 0) {
						hc = hc_list01.get(0);
					}
					if (hc_list02 != null && hc_list02.size() > 0) {
						knj = hc_list02.get(0);
					}
					logger.info("查询精英的耗材：" + hc);
					logger.info("查询精英的耗材：" + knj);

					// 精英采浆记录
					cRecord.setIDNo(gjz.getSFZ());
					cRecord.setAssayNo("0");// 化检编号

					cRecord.setSmallNo(providerRegister.getSmallNo());
					cRecord.setProviderNo(gjz.getCARDID());

					cRecord.setCollectionDate(DateTools.getInstance().dateFormatZero(ap.getSTART_TIME()));
					int worker = 0;
					if (ap.getUSERID() != null && !"".equals(ap.getUSERID()) && ap.getUSERID().length() > 3) {
						if (NumberTools.getInstance().isNumeric2(ap.getUSERID().substring(3))) {
							worker = Integer.parseInt(ap.getUSERID().substring(3));
						}
					}
					cRecord.setIsCollection("1");
					cRecord.setCollectionWorker(worker + "");// 护士ID
					// cRecord.setPlasmano(pcode);//血浆编号
					cRecord.setIsAuditing("1");
					if (ap.getNUMS() >= 590) {
						cRecord.setPlasmaGross(600 + "");
					} else {
						cRecord.setPlasmaGross(ap.getNUMS() + "");
					}
					long runtime = ap.getCOLLTAKEN() / 60;
					if(runtime > 100){
						//如果得到的时间出现异常，那么自动生成一个基于 30 -- 50 之间的一个随机数 作为运行时间
						runtime = new Random().nextInt(50 - 30 + 1) + 30;
					}
					
					
					cRecord.setCycleTimes(String.valueOf(ap.getCYCLES()));
					cRecord.setRunTime(String.valueOf(runtime));
					cRecord.setAnticoagulant((int)ap.getANTI_NUMS() + "");
					cRecord.setBloodGross(ap.getTOTAL_NUMS() + "");
					
					
					if(cRecord.getPlasmaGross().equals("600")){
						if(runtime<20){
							exceptionCollections.setRuntime(String.valueOf(runtime));
							runtime=20;
							cRecord.setRunTime(String.valueOf(runtime));
						}
						
						if(ap.getANTI_NUMS()<60){
							exceptionCollections.setAnticoagulant(ap.getANTI_NUMS() +"");
							int anticoagulant=new Random().nextInt(10) +60;
							cRecord.setAnticoagulant(anticoagulant+ "");
						}
						if(ap.getTOTAL_NUMS()<1000){
							exceptionCollections.setBloodGross(ap.getTOTAL_NUMS()+""); 	
							int BloodGross=new Random().nextInt(10) +1100;
							cRecord.setBloodGross(BloodGross+"");
						}
						if(ap.getCYCLES()<2){
							exceptionCollections.setCycleTimes(ap.getCYCLES()+"");
							cRecord.setCycleTimes("2");
						}
					}
					
					

					// 机器信息
					cRecord.setMachineNo(ap.getMAC_ID());
					cRecord.setMachineStatus("1");
					if (ap.getNUMS() >= 590) {
						cRecord.setCollectionInstance("1");// 采浆量是否足够
					} else {
						cRecord.setCollectionInstance("0");// 采浆量是否足够
					}
					cRecord.setCJYZ("是");
					if (hc != null && knj != null) {
						cRecord.setFactoryPlasmaNo(hc.getHCBM() + "|" + knj.getHCBM());
						cRecord.setTempletNovar(hc.getHCBM() + "" + knj.getHCBM());
						logger.info("模板编号：" + cRecord.getTempletNovar());
					}
					cRecord.setCJJX("ZXDC");
					cRecord.setRemark("");
					if (ap.getSFYCL() == 1) {
						cRecord.setCollectionResult("1");
					} else {
						cRecord.setCollectionResult("0");
					}
					cRecord.setIsAuditing("0");
					cRecord.setAssessor("0");

					String d = DateTools.getInstance().dateFormat(new Date(0L), "yyyy-MM-dd");
					cRecord.setOrg_id("0");
					cRecord.setUpdate_flag("2");
					cRecord.setUpdate_date(d);
					cRecord.setWeb_flag("-1");

					cRecord.setOrg_id_SW("0");
					cRecord.setUpdate_flag_SW("2");
					cRecord.setUpdate_date_SW(d);
					cRecord.setWeb_flag_SW("-1");

					cRecord.setOrg_id_QT("0");
					cRecord.setUpdate_flag_QT("2");
					cRecord.setUpdate_date_QT(d);
					cRecord.setWeb_flag_QT("-1");

					cRecord.setIF_GDJY(providerRegister.getIF_GDJY());
					cRecord.setCollectiondate_info(nowStr);

					logger.info("回写精英采浆结束 ，登记号：" + providerRegister.getSmallNo());

					// 回写建档记录中的最后采浆日期 总浆数加加一
					ProviderBaseInfo base = new ProviderBaseInfo();
					base.setProviderNo(gjz.getCARDID());
       
					List<ProviderBaseInfo> baseList = providerBaseInfoMapper.getProviderBaseInfo(base);

					if (baseList != null && baseList.size() == 1) {
						base = baseList.get(0);
						base.setCollectionDate(DateTools.getInstance().dateFormatZero(nowStr));
						Calendar next_day = Calendar.getInstance();
						next_day.setTime(now);
						next_day.add(Calendar.DAY_OF_YEAR, 14);

						base.setLastDateBooking(DateTools.getInstance().dateFormat(next_day.getTime(), "yyyy-MM-dd"));
						logger.info("回写建档记录中【" + gjz.getXM() + "】的最后采浆日期为今天！");
						//总采浆次数加1
						base.setTimes( String.valueOf(Integer.valueOf(base.getTimes())+1));
						logger.info("回写建档记录中【" + gjz.getXM() + "】的总采浆次数"+base.getTimes());
					}

					logger.info("写精英的耗材使用量  start");

					KUSE kuse = new KUSE();
					KUSEList uList_1 = new KUSEList();

					String nullDate = DateTools.getInstance().dateFormat(now, "yyyy-MM-dd");
					String useno = "S" + DateTools.getInstance().dateFormat(now, "yyMMdd") + "0001";
					kuse.setUseNo(useno);
					kuse.setDepotNo(1+"");
					kuse.setUseDate(nullDate);
					kuse.setRemark("采浆模块使用耗材");
					kuse.setIfFlow("1");
					kuse.setModeUser("采浆");
					kuse.setIsAuditing("0");
					kuse.setAssessor("0");
					kuse.setDepotNo("1");
					kuse.setOrg_id("028008002001");
					kuse.setUpdate_flag("1");
					kuse.setUpdate_date(DateTools.getInstance().dateFormatZero("1905-03-14 00:00:00"));
					kuse.setWeb_flag("-1");
					kuse.setOrg_id_SW("0");
					kuse.setUpdate_flag_SW("-1");
					kuse.setUpdate_date_SW(DateTools.getInstance().dateFormatZero("1900-01-01 00:00:00"));
					kuse.setWeb_flag_SW("-1");
					kuse.setOrg_id_QT("0");
					kuse.setUpdate_flag_QT("1");
					kuse.setUpdate_date_QT(DateTools.getInstance().dateFormatZero("1900-01-01 00:00:00"));
					kuse.setWeb_flag_QT("-1");

					uList_1.setDepotNo(useno);
					uList_1.setMaterialNo(hc.getMaterialNo());
					uList_1.setPH(hc.getPH());
					uList_1.setUnits(hc.getUnits());
					uList_1.setNumber("1");
					uList_1.setDepotNo("1");
					uList_1.setIfOut("0");
					uList_1.setXQ(hc.getXQ());
					uList_1.setBegDate(hc.getBegDate());
					uList_1.setEndDate(hc.getEndDate());
					uList_1.setRemark("采浆模块使用耗材");
					uList_1.setOperateDate(nullDate);
					uList_1.setProviderNo(gjz.getCARDID());

					userSet userSet = new userSet();
					userSet.setPERSONID(ap.getUSERID());
					DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
					List<userSet> userList = userSetMapper.selectByuserSet(userSet);

					String optionerName = "";// 操作员
					if (userList != null && userList.size() > 0) {
						optionerName = userList.get(0).getPERSONNAME();
					}

					uList_1.setOperater(optionerName);
					uList_1.setSmallno(cRecord.getCollectionNo() + "");
					uList_1.setModeUser("采浆");
					// uList_1.setOrgId("028008002001");
					// uList_1.setUpdateFlag(1);
					// uList_1.setUpdateDate(DateTools.getInstance().stringFormat("1905-03-14
					// 00:00:00.000", "yyyy-MM-dd HH:mm:ss:SSS"));
					// uList_1.setWebFlag(-1);
					// uList_1.setOrgIdSw("0");
					// uList_1.setUpdateFlagSw(-1);
					// uList_1.setUpdateDateSw(DateTools.getInstance().stringFormat("1900-01-01
					// 00:00:00.000", "yyyy-MM-dd HH:mm:ss:SSS"));
					// uList_1.setWebFlagSw(-1);
					// uList_1.setOrgIdQt("0");
					// uList_1.setUpdateFlagQt(1);
					// uList_1.setUpdateDateQt(DateTools.getInstance().stringFormat("1900-01-01
					// 00:00:00.000", "yyyy-MM-dd HH:mm:ss:SSS"));
					// uList_1.setWebFlagQt(-1);

					KUSEList uList_2 = new KUSEList();
					uList_2.setUseNo(useno);
					uList_2.setMaterialNo(knj.getMaterialNo());
					uList_2.setPH(knj.getPH());
					uList_2.setUnits(knj.getUnits());
					uList_2.setNumber("1");
					uList_2.setDepotNo("1");
					uList_2.setIfOut("0");
					uList_2.setXQ(knj.getXQ());
					uList_2.setBegDate(knj.getBegDate());
					uList_2.setEndDate(knj.getEndDate());
					uList_2.setRemark("采浆模块使用耗材");
					uList_2.setOperateDate(nullDate);
					uList_2.setProviderNo(gjz.getCARDID());
					uList_2.setOperater(optionerName);
					uList_2.setSmallno(cRecord.getCollectionNo() + "");
					uList_2.setModeUser("采浆");
					// uList_2.setOrgId("028008002001");
					// uList_2.setUpdateFlag(1);
					// uList_2.setUpdateDate(DateTools.getInstance().stringFormat("1905-03-14
					// 00:00:00.000", "yyyy-MM-dd HH:mm:ss:SSS"));
					// uList_2.setWebFlag(-1);
					// uList_2.setOrgIdSw("0");
					// uList_2.setUpdateFlagSw(-1);
					// uList_2.setUpdateDateSw(DateTools.getInstance().stringFormat("1900-01-01
					// 00:00:00.000", "yyyy-MM-dd HH:mm:ss:SSS"));
					// uList_2.setWebFlagSw(-1);
					// uList_2.setOrgIdQt("0");
					// uList_2.setUpdateFlagQt(1);
					// uList_2.setUpdateDateQt(DateTools.getInstance().stringFormat("1900-01-01
					// 00:00:00.000", "yyyy-MM-dd HH:mm:ss:SSS"));
					// uList_2.setWebFlagQt(-1);

					String hc_num = hc.getNumber();// 耗材剩余量

					int num = Integer.parseInt(hc_num.substring(0, hc_num.indexOf(".")));
					hc.setNumber((num - 1) + "");

					String knj_num = knj.getNumber();// 抗凝剂剩余量

					num = Integer.parseInt(knj_num.substring(0, knj_num.indexOf(".")));
					knj.setNumber((num - 1) + "");

					logger.info("写精英的耗材使用量  end");

					// 回写精英登记表
					DataSourceContextHolder.setDataSourceType(DataSourceConst.jingying);
					providerRegister.setIsCollection("1");
					providerRegisterMapper.updateProviderRegister(providerRegister);
					if (cRecord.getCollectionResult() == "1") {

						logger.info("写精英的日志：采浆记录  start");

						try {
							SystemLogJiaying sysLog = new SystemLogJiaying();
							SystemLogJiaying sysLog2 = new SystemLogJiaying();

							String modeName = "采浆记录";

							sysLog.setModeName(modeName);
							String optionInfo = "操作员：" + optionerName + " 把供浆员：" + gjz.getXM() + "，编号为：" + gjz.getCARDID()
									+ "采浆预约日期修改为：" + nullDate;
							sysLog.setOptioninfo(optionInfo);
							sysLog.setOptionter(worker + "");
							sysLog.setOptionterdate(nowStr);
							sysLog.setOptdate(nowStr);
							sysLog.setOptdate(nullDate);

							sysLog.setDelbat("0");
							sysLog.setSynDate(nullDate);
							sysLog.setModify_time(nowStr);

							sysLog2.setModeName(modeName);
							String optionInfo1 = "操作员：" + optionerName + " 把供浆员：" + gjz.getXM() + "，编号为：" + gjz.getCARDID()
									+ "采浆为：合格";
							sysLog2.setOptioninfo(optionInfo1);
							sysLog2.setOptionter(worker + "");
							sysLog2.setOptionterdate(nowStr);
							sysLog2.setOptdate(nowStr);
							sysLog2.setOptdate(nullDate);
							sysLog2.setSynDate(nullDate);
							sysLog2.setModify_time(nowStr);
							sysLog2.setDelbat("0");
							DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
							systemLogJiayingMapper.addSystemLog(sysLog);
							systemLogJiayingMapper.addSystemLog(sysLog2);

						} catch (Exception e) {
							logger.info("写精英的日志：采浆记录  异常：" + e.getMessage());
						}
						logger.info("写精英的日志：采浆记录  end");
						DataSourceContextHolder.setDataSourceType(DataSourceConst.jingying);
						kUSEListMapper.addKUSEList(uList_1);
						kUSEListMapper.addKUSEList(uList_2);
						kHCSLMapper.updateKHCSL(hc);
						kHCSLMapper.updateKHCSL(knj);
						kUSEMapper.addKUSE(kuse);
						kUSEMapper.addKUSE(kuse);

						providerBaseInfoMapper.updateProviderBaseInfo(base);

					}
					
					//保存异常采浆记录
					if (exceptionCollections.getAnticoagulant()!=null||exceptionCollections.getBloodGross()!=null||
							exceptionCollections.getCycleTimes()!=null||exceptionCollections.getRuntime()!=null) {
						DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
						exceptionCollectionsMapper.saveExceptionCollections(exceptionCollections);
					}
					
					DataSourceContextHolder.setDataSourceType(DataSourceConst.jingying);
					if (cRecord.getCollectionNo() != null && !"".equals(cRecord.getCollectionNo())) {
						collectionRecordMapper.updateCollectionRecord(cRecord);
					} else {
						collectionRecordMapper.addCollectionRecord(cRecord);
					}
				}
				
				
				
				

				successAp.add(ap);

				logger.info("同步的供浆者【" + ap.getSFZ() + "】采浆信息结束~~~");
			} catch (Exception e) {
				e.printStackTrace();
				logger.info("同步的供浆者【" + ap.getSFZ() + "】采浆信息异常，异常信息：" + e.getMessage());
			}
		}
		DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
		// 更新佳颖数据库中的同步时间
		for (Aphereses ap : successAp) {
			try {
				logger.info("更新同步供浆者【" + ap.getSFZ() + "】采浆信息的同步状态开始~~~");

				ap.setSYNDATE(nowStr);
				// 这里将同步时间修改为现在
				apheresesMapper.updateAphereses(ap);

				logger.info("更新同步的供浆者【" + ap.getSFZ() + "】采浆信息的同步状态结束~~~");
			} catch (Exception e) {
				e.printStackTrace();
				logger.info("更新供浆者【" + ap.getSFZ() + "】采浆信息的同步状态异常，异常信息：" + e.getMessage());
			}
		}

	}

	@Override
	public void doCostExec() throws Exception {
		Date now = new Date();
		String nowStr = DateTools.getInstance().dateFormat(now, "yyyy-MM-dd HH:mm:ss");
		String nowStrZero = DateTools.getInstance().dateFormat(now, "yyyy-MM-dd");

		GJZ_Cost_Release gjzCost = new GJZ_Cost_Release();
		gjzCost.setMODIFY_TIME(nowStr);
		DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
		List<GJZ_Cost_Release> costList = GJZ_Cost_ReleaseMapper.selectByCost(gjzCost );

		logger.info("待同步的供浆者费用发放信息 记录数=" + costList.size());
		List<GJZ_Cost_Release> successCost = new ArrayList<GJZ_Cost_Release>();
		
		
		for (GJZ_Cost_Release cost : costList) {

			try {

				logger.info("同步的供浆者【" + cost.getGJZID() + "】费用信息开始~~~");
				
				DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
				GJZXX gjz = new GJZXX();
				gjz.setID(cost.getGJZID());
				List<GJZXX> gjzList = GJZXXMapper.getGJZXX(gjz);
				if (gjzList != null && gjzList.size() > 0) {
					gjz = gjzList.get(0);
				} else {
					logger.info("同步的供浆者【" + cost.getGJZID() + "】费用信息失败，没有找到供浆者基本信息 ~~~");
					continue;
				}
				DataSourceContextHolder.setDataSourceType(DataSourceConst.jingying);
				ProviderRegister providerRegister = new ProviderRegister();
				providerRegister.setRegistDate(nowStrZero);
				providerRegister.setIDNo(gjz.getSFZ());
				List<ProviderRegister> regList = providerRegisterMapper.getProviderRegister(providerRegister);
				if (regList != null && regList.size() > 0) {
					providerRegister = regList.get(0);
				} else {
					logger.info("同步的供浆者【" + cost.getGJZID() + "】费用信息失败，没有找到供浆者在精英的登记信息 ~~~");
					continue;
				}
				
//				Aphereses ap = new Aphereses();
//				ap.setPROC_ID(cost.getPROC_ID());
//				
//				List<Aphereses> apList = apheresesMapper.selectByCj(ap);
//				if(apList != null && apList.size()>0){
//					ap = apList.get(0);
//				}
				
				// 精英费用发放记录
//				String collectionDate = DateTools.getInstance().dateFormatZero(ap.getSTART_TIME());
				CollectionRecord collection = new CollectionRecord();
				collection.setProviderNo(gjz.getCARDID());
				collection.setSmallNo(providerRegister.getSmallNo());
				
				List<CollectionRecord> collections = collectionRecordMapper.getCollectionRecord(collection);
				String collectionNo = "0";
				if (collections != null && collections.size() == 1) {
					collection = collections.get(0);
					collectionNo = collection.getCollectionNo();
				}

				if(  !"1".equals(collection.getIsCollection())){
					logger.info("同步的供浆者【" + cost.getGJZID() + "】费用信息失败，没有找到供浆者在精英的采浆信息 ~~~");
					continue;
				}
				

				RateRecord rr = new RateRecord();
				rr.setProviderNo(gjz.getCARDID());
				rr.setSmallNo(providerRegister.getSmallNo());
				List<RateRecord> rrs = rateRecordMapper.getRateRecord(rr);
				


				if (rrs != null && rrs.size() > 0) {
					rr = rrs.get(0);
				}else{
					rr.setCollectionNo(collectionNo);

					String nullDate = DateTools.getInstance().dateFormat(new Date(0L), "yyyy-MM-dd");
					
					rr.setIsAuditing("0");
					rr.setAssessor("0");
					rr.setOrg_id("0");
					rr.setUpdate_flag("2");
					rr.setUpdate_date(nullDate);
					rr.setWeb_flag("-1");
					rr.setOrg_id_SW("0");
					rr.setUpdate_flag_SW("2");
					rr.setUpdate_date_SW(nullDate);
					rr.setWeb_flag_SW("-1");
					rr.setOrg_id_QT("0");
					rr.setUpdate_flag_QT("2");
					rr.setUpdate_date_QT(nullDate);
					rr.setWeb_flag_QT("-1");
					rr.setYQ_FY("0.0");
					rr.setTM_FY("0.0");
					rr.setCjcsbtje("0.0");
					rr.setLJWFBTJE("0.0");
					rr.setBus_KM("0.0");
					rr.setAXKZS("0");
					rr.setAXDHJE("0.0");
					rr.setDHJQJE("0.0");
					rr.setDs_YYCF("0.0");
					rr.setJSR_FY("0.0");
					rr.setWGBT_RNMTBSW("0.0");
					rr.setRnmlskk("0.0");
				}

				rr.setIF_GDJY(providerRegister.getIF_GDJY());

				if (cost.getCRETIME() != null && !"".equals(cost.getCRETIME())) {
					providerRegister.setIsRate("1");
					rr.setPutOutDate(DateTools.getInstance().dateFormatZero(cost.getCRETIME()));
					rr.setIsPutOut("1");
				}else{
					rr.setIsPutOut("0");
				}

				rr.setIDNo(gjz.getSFZ());
				rr.setProviderNo(gjz.getCARDID());
				rr.setSmallNo(providerRegister.getSmallNo());
				rr.setCollectionDate(collection.getCollectionDate());
				rr.setPutOutMoney(cost.getSJJE()+"");
				rr.setTMMoney("0.0");
				rr.setCjcsbtje(cost.getTIMESALLOWANCE() +"");
				
				int worker = 0;
				if (cost.getCREATENURSE() != null && !"".equals(cost.getCREATENURSE()) && cost.getCREATENURSE().length() > 3) {
					if (NumberTools.getInstance().isNumeric2(cost.getCREATENURSE().substring(3))) {
						worker = Integer.parseInt(cost.getCREATENURSE().substring(3));
					}
				}
				rr.setPutWorker(worker+"");
				rr.setBase_FY(cost.getJCJE()+"");
				rr.setTrafficFee(cost.getJTF()+"");
				rr.setPlasmaGross(collection.getPlasmaGross());
				rr.setCollectionWorker(collection.getCollectionWorker());

				providerRegisterMapper.updateProviderRegister(providerRegister);
				if(rr.getSerial() != null && !"".equals(rr.getSerial())){
					rateRecordMapper.updateRateRecord(rr);
				}else{
					rateRecordMapper.addRateRecord(rr);
				}

				successCost.add(cost);

				logger.info("同步的供浆者【" + gjz.getCARDID() + "】费用信息结束~~~");
			} catch (Exception e) {
				e.printStackTrace();
				logger.info("同步的供浆者【" + cost.getGJZID() + "】费用信息异常，异常信息：" + e.getMessage());
			}
		}
		DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
		// 更新佳颖数据库中的同步时间
		for (GJZ_Cost_Release cost : successCost) {
			try {
				logger.info("更新同步的供浆者【" + cost.getGJZID() + "】费用信息的同步状态开始~~~");

				cost.setSYNDATE(nowStr);
				// 这里将同步时间修改为现在
				GJZ_Cost_ReleaseMapper.updateCost(cost);
				logger.info("更新同步的供浆者【" + cost.getGJZID() + "】费用信息的同步状态结束~~~");
			} catch (Exception e) {
				e.printStackTrace();
				logger.info("更新供浆者【" + cost.getGJZID() + "】费用信息的同步状态异常，异常信息：" + e.getMessage());
			}
		}
	}

	@Override
	public void doHeatExec() throws Exception {
		Date now = new Date();
		String nowStr = DateTools.getInstance().dateFormat(now, "yyyy-MM-dd HH:mm:ss");
		String nowStrZero = DateTools.getInstance().dateFormat(now, "yyyy-MM-dd");
		DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
		GJZ_Heat gHeat = new GJZ_Heat();
		gHeat.setMODIFY_TIME(nowStr);
		
		List<GJZ_Heat> heatList = GJZ_HeatMapper.selectByHeat(gHeat);
		
		logger.info("待同步的血浆热合信息 记录数=" + heatList.size());

		List<GJZ_Heat> successHeat = new ArrayList<GJZ_Heat>();

		for (GJZ_Heat heat : heatList) {
			try {
				
				DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
				GJZXX gjz = new GJZXX();
				gjz.setID(heat.getGJZID());
				List<GJZXX> gjzList = GJZXXMapper.getGJZXX(gjz);
				if (gjzList != null && gjzList.size() > 0) {
					gjz = gjzList.get(0);
				} else {
					logger.info("同步的供浆者【" + heat.getGJZID() + "】热合信息失败，没有找到供浆者基本信息 ~~~");
					continue;
				}
				DataSourceContextHolder.setDataSourceType(DataSourceConst.jingying);
				ProviderRegister providerRegister = new ProviderRegister();
				providerRegister.setRegistDate(nowStrZero);
				providerRegister.setIDNo(gjz.getSFZ());
				List<ProviderRegister> regList = providerRegisterMapper.getProviderRegister(providerRegister);
				if (regList != null && regList.size() > 0) {
					providerRegister = regList.get(0);
				} else {
					logger.info("同步的供浆者【" + heat.getGJZID() + "】热合信息失败，没有找到供浆者在精英的登记信息 ~~~");
					continue;
				}
				
				CollectionRecord collection = new CollectionRecord();
				collection.setProviderNo(gjz.getCARDID());
				collection.setSmallNo(providerRegister.getSmallNo());
				
				List<CollectionRecord> collections = collectionRecordMapper.getCollectionRecord(collection);
				if (collections != null && collections.size() == 1) {
					collection = collections.get(0);
				}

				if(!"1".equals(collection.getIsCollection())){
					logger.info("同步的供浆者【" + heat.getGJZID() + "】热合信息失败，没有找到供浆者在精英的采浆信息 ~~~");
					continue;
				}
				

				PlasmStock tps = new PlasmStock();
				tps.setSmallNo(providerRegister.getSmallNo());
				List<PlasmStock> tpss = plasmStockMapper.getPlasmStock(tps);
				
				if (tpss != null && tpss.size() > 0) {
					
				}else{
					tps.setCollectionNo("0");// 这个是0，就是待办的，就会显示到精英系统界面的左边
					tps.setIsOut("1");//检疫期数据设置成1才能查看到
					tps.setIsAuditing("0");
					tps.setAssessor("0");
					tps.setOrg_id("0");
					tps.setUpdate_flag("2");
					tps.setUpdate_date(DateTools.getInstance().dateFormatZero("1900-01-01 00:00:00"));
					tps.setWeb_flag("-1");
					tps.setIssep("0");
					tps.setOrg_id_SW("0");
					tps.setUpdate_flag_SW("2");
					tps.setUpdate_date_SW(DateTools.getInstance().dateFormatZero("1900-01-01 00:00:00"));
					tps.setWeb_flag_SW("-1");
					tps.setOrg_id_QT("0");
					tps.setUpdate_flag_QT("2");
					tps.setUpdate_date_QT(DateTools.getInstance().dateFormatZero("1900-01-01 00:00:00"));
					tps.setWeb_flag_QT("-1");
					tps.setIF_GDJY(providerRegister.getIF_GDJY());
					tps.setProviderNoType("1");
					tps.setAvalue("0.0");

					tps.setPlasmaType("1");
					tps.setIDNo(gjz.getSFZ());
					tps.setProviderNo(gjz.getCARDID());
					tps.setSmallNo(providerRegister.getSmallNo());
					tps.setCollectionDate(collection.getCollectionDate());
					tps.setCollectionTime(collection.getCollectiondate_info());
					tps.setCollectionWorker(collection.getCollectionWorker());
					tps.setInPacker("0");
					// 采浆量
					tps.setPlasmaGross(collection.getPlasmaGross());
					
					plasmStockMapper.addPlasmStock(tps);
					
					logger.info("保存精英热合信息结束");
				}
				successHeat.add(heat);
				logger.info("同步血浆【" + heat.getHID() + "】热合信息结束~~~");
			} catch (Exception e) {
				e.printStackTrace();
				logger.info("同步的血浆【" + heat.getHID() + "】热合信息异常，异常信息：" + e.getMessage());
			}
		}
		DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
		// 更新佳颖数据库中的同步时间
		for (GJZ_Heat heat : successHeat) {
			try {
				logger.info("更新同步血浆【" + heat.getHID() + "】热合信息的同步状态开始~~~");

				heat.setSYNDATE(nowStr);
				// 这里将同步时间修改为现在
				GJZ_HeatMapper.updateHeat(heat);
				logger.info("更新同步血浆【" + heat.getHID() + "】热合信息的同步状态结束~~~");
			} catch (Exception e) {
				e.printStackTrace();
				logger.info("更新同步血浆【" + heat.getHID() + "】热合信息的同步状态异常，异常信息：" + e.getMessage());
			}
		}
	}

	@Override
	public void doXpExec() throws Exception {
		Date now = new Date();
		String nowStr = DateTools.getInstance().dateFormat(now, "yyyy-MM-dd HH:mm:ss");

		GJZXPCheck gCheck = new GJZXPCheck();
		gCheck.setMODIFY_TIME(nowStr);
		DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
		List<GJZXPCheck> xpList = GJZXPCheckMapper.selectByXPCheck(gCheck );
		
		logger.info("待同步的供浆者胸片信息 记录数=" + xpList.size());

		List<GJZXPCheck> successXp = new ArrayList<GJZXPCheck>();//

		for (GJZXPCheck xp : xpList) {

			try {
				logger.info("同步的供浆者【" + xp.getGJZID() + "】胸片信息开始~~~");
				
				DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
				GJZXX gjz = new GJZXX();
				gjz.setID(xp.getGJZID());
				List<GJZXX> gjzList = GJZXXMapper.getGJZXX(gjz);
				if (gjzList != null && gjzList.size() > 0) {
					gjz = gjzList.get(0);
				} else {
					logger.info("同步的供浆者【" + xp.getGJZID() + "】胸片信息失败，没有找到供浆者基本信息 ~~~");
					continue;
				}


				
				if (xp.getXTSJ() != null && !"".equals(xp.getXTSJ())) {
					
					String xtsj = DateTools.getInstance().dateFormatZero(xp.getXTSJ());
					
					BodyCheckLastRecord tl = new BodyCheckLastRecord();
					tl.setProviderNo(gjz.getCARDID());
					tl.setXTSJ(xtsj);
					DataSourceContextHolder.setDataSourceType(DataSourceConst.jingying);
					List<BodyCheckLastRecord> bcList = bodyCheckLastRecordMapper.getBodyCheckLastRecord(tl);
					
					boolean flag = false;
					if (bcList != null && bcList.size() > 0) {
						tl = bcList.get(0);
						flag = true;
					}
					
					tl.setProviderNo(gjz.getCARDID());
					tl.setLastbodycheckdate(xtsj);
					int worker = 10;
					if (xp.getXPJLR() != null && !"".equals(xp.getXPJLR()) && xp.getXPJLR().length() > 3) {
						if (NumberTools.getInstance().isNumeric2(xp.getXPJLR().substring(3))) {
							worker = Integer.parseInt(xp.getXPJLR().substring(3));
						}
					}
					tl.setLastbodychecker(worker+"");
					tl.setXTSJ(xtsj);
					tl.setXTYS(xp.getXTYS());
					tl.setXTDW(xp.getXTDW());
					tl.setOrg_id("0");
					tl.setUpdate_flag("2");
					tl.setUpdate_date(DateTools.getInstance().dateFormatZero("1900-01-01 00:00:00"));
					tl.setWeb_flag("-1");
					tl.setOrg_id_SW("0");
					tl.setUpdate_flag_SW("2");
					tl.setUpdate_date_SW(DateTools.getInstance().dateFormatZero("1900-01-01 00:00:00"));
					tl.setWeb_flag_SW("-1");
					tl.setOrg_id_QT("0");
					tl.setUpdate_flag_QT("2");
					tl.setUpdate_date_QT(DateTools.getInstance().dateFormatZero("1900-01-01 00:00:00"));
					tl.setWeb_flag_QT("-1");

					int sftg = xp.getSFTG();
					if (sftg == 1) {
						tl.setXTGG("合格");
					} else {
						tl.setXTGG("不合格");
					}
					
					if(flag){
						bodyCheckLastRecordMapper.updateBodyCheckLastRecord(tl);
					}else{
						bodyCheckLastRecordMapper.addBodyCheckLastRecord(tl);
					}
					successXp.add(xp);
				}

				logger.info("同步的供浆者【" + xp.getGJZID() + "】胸片信息结束~~~");
			} catch (Exception e) {
				e.printStackTrace();
				logger.info("同步的供浆者【" + xp.getGJZID() + "】胸片信息异常，异常信息：" + e.getMessage());
			}
		}
		DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
		// 更新佳颖数据库中的同步时间
		for (GJZXPCheck xp : successXp) {
			try {
				logger.info("更新同步的供浆者【" + xp.getGJZID() + "】胸片信息的同步状态开始~~~");

				xp.setSYNDATE(nowStr);
				// 这里将同步时间修改为现在
				GJZXPCheckMapper.updateGJZXPCheck(xp);
				logger.info("更新同步的供浆者【" + xp.getGJZID() + "】胸片信息的同步状态结束~~~");
			} catch (Exception e) {
				e.printStackTrace();
				logger.info("更新供浆者【" + xp.getGJZID() + "】胸片信息的同步状态异常，异常信息：" + e.getMessage());
			}
		}
	}

	@Override
	public void doLogExec() throws Exception {
		Date now = new Date();
		String nowStr = DateTools.getInstance().dateFormat(now, "yyyy-MM-dd HH:mm:ss");
		DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
		SystemLogJiaying j_log = new SystemLogJiaying();
		j_log.setModify_time(nowStr);
		
		List<SystemLogJiaying> logList = systemLogJiayingMapper.selectSystemLogJiaying(j_log);
		
		logger.info("待同步的供浆者日志信息 记录数=" + logList.size());

		List<SystemLogJiaying> successLog = new ArrayList<SystemLogJiaying>();

		for (SystemLogJiaying log : logList) {

			try {
				logger.info("同步的供浆者【" + log.getOptionID() + "】日志信息开始~~~");

				SystemLog sysOptionter = new SystemLog();
				

//				if (log.getModename().equals("发卡")) {
//					String optioninfo = log.getOptioninfo();
//
//					int idx = optioninfo.indexOf("改成编号为：");
//					String cardId = optioninfo.substring(idx + 6, idx + 12);
//
//					List<tproviderbaseinfo> baseInfoList = tproviderbaseinfoJDBCUnit.getInstance().load(jydb,
//							"ProviderNo = '" + cardId + "'", null, 1);
//					if (baseInfoList != null && baseInfoList.size() > 0) {
//						tproviderbaseinfo bi = baseInfoList.get(0);
//
//						optioninfo += bi.getIcno();// ic卡号
//					}
//
//					log.setOptioninfo(optioninfo);
//				}
				DataSourceContextHolder.setDataSourceType(DataSourceConst.jingying);
				sysOptionter.setModeName(log.getModeName());
				sysOptionter.setOptioninfo(log.getOptioninfo());
				sysOptionter.setOptionter(log.getOptionter());
				sysOptionter.setOptionterdate(log.getOptionterdate());
				sysOptionter.setOptdate(DateTools.getInstance().dateFormatZero(log.getOptdate()));
				sysOptionter.setDelbat("0");
				systemLogMapper.addSystemLog(sysOptionter);
				successLog.add(log);
				logger.info("同步的供浆者【" + log.getOptionID() + "】日志信息结束~~~");
			} catch (Exception e) {
				e.printStackTrace();
				logger.info("同步的供浆者【" + log.getOptionID() + "】日志信息异常，异常信息：" + e.getMessage());
			}
		}
		DataSourceContextHolder.setDataSourceType(DataSourceConst.mx);
		// 更新佳颖数据库中的同步时间
		for (SystemLogJiaying log : successLog) {
			try {
				logger.info("更新同步的供浆者【" + log.getOptionID() + "】日志信息的同步状态开始~~~");

				log.setSynDate(nowStr);
				// 这里将同步时间修改为现在
				systemLogJiayingMapper.updateSystemLogJiaying(log);
				logger.info("更新同步的供浆者【" + log.getOptionID() + "】日志信息的同步状态结束~~~");
			} catch (Exception e) {
				e.printStackTrace();
				logger.info("更新供浆者【" + log.getOptionID() + "】日志信息的同步状态异常，异常信息：" + e.getMessage());
			}
		}
	}

	private byte[] getByte(byte[] value) throws IOException {
		byte[] c = null;
		if (null != value) {
			java.io.ByteArrayInputStream bin = new java.io.ByteArrayInputStream(value);
			try {
				java.io.DataInputStream in = new java.io.DataInputStream(bin);
				try {
					in.readUTF();
					in.readUTF();
					in.readInt();
					c = new byte[in.available()];
					in.read(c, 0, c.length);
				} finally {
					in.close();
				}
			} finally {
				bin.close();
			}
		}
		return c;
	}

}
